import React from 'react';
import {useSelector, useDispatch} from 'react-redux';
import {contralTestActive} from '@/views/redux/reduxToolkit/module/contral';
const ReduxToolkit = () => {

    const dispatch = useDispatch();
    const value = useSelector(state => state.counter.value);
    const testActive = useSelector(state => state.counter.testActive);
    const handleAsync = () => {
        dispatch(contralTestActive()).then((res) => {
            dispatch({
                type: 'contral/changeTestActive',
                payload: res.payload
            });
        });
    }
    return (
        <div>
            <h1>Redux Toolkit Example</h1>
            {value}s{testActive} <button onClick={() => dispatch({type: 'counter/increment',payload: 1} as any)}>Increment</button>
            {/*<button onClick={() => dispatch(contralTestActive() as any)}>Decrement</button>*/}
            <button onClick={handleAsync}>Decrement</button>
        </div>
    );
};

export default ReduxToolkit;